﻿/*

    This file is a part of BinaryDialog.
 
    BiLog IM aka BinaryDialog - WPF Client for XMPP Protocol
    Copyright (C) 2008  Christophe LEMOINE

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Composition;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;
using System.IO;
using System.Globalization;

using BinaryDialog;
using BinaryDialog.Datas;

namespace BinaryDialog.Core.Relationship
{

    [ValueConversion(typeof(Account), typeof(string))]
    public class AccountsConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            switch((string)parameter)
            {
                case "ConnectedOpacity":
                    if (value == null) { return null; }
                    return (((bool)value) ? 0.5 : 1.0);
                case "ConnectedFontStyle":
                    if (value == null) { return null; }
                    return (((bool)value) ? FontStyles.Italic : FontStyles.Normal);
                case "Avatar":
                    if (value != null)
                    {
                        MemoryStream ms = new MemoryStream((byte[])value);
                        BitmapDecoder bd = BitmapDecoder.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                        return bd.Frames[0];
                    }
                    else
                    {
                        return BitmapFrame.Create(new Uri("pack://application:,,,/Icons/user-info.png", UriKind.RelativeOrAbsolute));
                    }
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

    }

}
